package hp.com.util;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.UUID;

public class RepeatSubmit {

    public static boolean get(HttpServletRequest request, HttpSession session) {
        String reqFormId = request.getParameter("submitFormId");
        String sessionFormId = (String)session.getAttribute("submitFormId");
        if (reqFormId.equals(sessionFormId)) {
            return true;
        }else {
            return false;
        }
    }

    public static void set(HttpServletRequest request, HttpSession session) {
        String uuid = UUID.randomUUID().toString();
        request.setAttribute("submitFormId",uuid);
        session.setAttribute("submitFormId",uuid);
    }
}
